package com.example.shaomengjie.smvp.net.http;

import com.example.shaomengjie.smvp.net.api.ApiService;
import com.example.shaomengjie.smvp.net.cache.CacheProvider;
import com.example.shaomengjie.smvp.net.parser.GsonTSpeaker;
import com.example.shaomengjie.smvp.utils.Constant;
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;

import io.rx_cache2.internal.RxCache;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by shaomengjie on 2017/6/20.
 */

public class BaseHttpMoudle {
    protected Retrofit mRetrofit;
    protected ApiService mApiService;
    protected final CacheProvider cacheProvider;
    public BaseHttpMoudle() {
        mRetrofit = new Retrofit.Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .baseUrl(Constant.BASE_URL)
                .client(HttpManager.getInstance().okHttpClient)
                .build();

        cacheProvider = new RxCache.Builder()
                .persistence(HttpManager.mContext.getFilesDir(), new GsonTSpeaker())
                .using(CacheProvider.class);

        mApiService = mRetrofit.create(ApiService.class);
    }
}
